package com.jichaoyun.common.utils;

import cn.hutool.poi.excel.ExcelWriter;
import cn.hutool.poi.excel.StyleSet;
import org.apache.poi.ss.usermodel.*;

import java.util.List;
import java.util.Map;

public class PoiExcelStyle {
    public static void setStyleSet(ExcelWriter wr, List<Map<String, Object>> resList) {
        // 设置列宽度
        for (int i = 0; i < resList.get(0).size(); i++) {
            wr.setColumnWidth(i, 20);
        }

        //设置表头
        StyleSet styleSet = wr.getStyleSet();
        CellStyle headCellStyle = styleSet.getHeadCellStyle();
        Font font1 = wr.createFont();
        font1.setBold(true);
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short)14);
        font1.setColor(Font.COLOR_NORMAL);

        headCellStyle.setFont(font1);
        headCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headCellStyle.setAlignment(HorizontalAlignment.CENTER);
        headCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        //设置表主体
        Font font2 = wr.createFont();
        font2.setFontName("宋体");
        font2.setFontHeightInPoints((short)12);
        CellStyle cellStyle = styleSet.getCellStyle();
        cellStyle.setFont(font2);
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    }

    public static void setStyleSet(ExcelWriter wr, List<Map<String, Object>> resList,Integer columnWith) {
        // 设置列宽度
        for (int i = 0; i < resList.get(0).size(); i++) {
            wr.setColumnWidth(i, columnWith);
        }

        //设置表头
        StyleSet styleSet = wr.getStyleSet();
        CellStyle headCellStyle = styleSet.getHeadCellStyle();
        Font font1 = wr.createFont();
        font1.setBold(true);
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short)14);
        font1.setColor(Font.COLOR_NORMAL);

        headCellStyle.setFont(font1);
        headCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headCellStyle.setAlignment(HorizontalAlignment.CENTER);
        headCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        //设置表主体
        Font font2 = wr.createFont();
        font2.setFontName("宋体");
        font2.setFontHeightInPoints((short)12);
        CellStyle cellStyle = styleSet.getCellStyle();
        cellStyle.setFont(font2);
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
    }

}
